package cn.hpu.mobile_bank.controller;


import cn.hpu.mobile_bank.dto.req.SelectTransRecordReq;
import cn.hpu.mobile_bank.dto.req.TransferFormReq;
import cn.hpu.mobile_bank.dto.resp.AllInAndOutResponse;
import cn.hpu.mobile_bank.dto.resp.ApiResult;
import cn.hpu.mobile_bank.dto.resp.TransRecordList;
import cn.hpu.mobile_bank.dto.resp.TransferRecordResponse;
import cn.hpu.mobile_bank.service.TransRecordService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/transRecord")
public class TransRecordController {

    @Autowired
    private TransRecordService transRecordService;
    @PostMapping("/transfer")
    @Operation(summary = "转账")
    public ApiResult<String> transfer(@RequestBody @Valid TransferFormReq transferFormReq) {
        return transRecordService.transfer(transferFormReq);
    }

    @GetMapping("/record/{id}")
    @Operation(summary = "交易记录")
    public ApiResult<TransferRecordResponse> record(@PathVariable Integer id) {
        return transRecordService.record(id);
    }

    @GetMapping("/all")
    @Operation(summary = "获取用户的总支出,总收入,总资产,账户数量")
    public ApiResult<AllInAndOutResponse> getAll() {
        return transRecordService.getAll();
    }
    @PostMapping("/allAccountRecord")
    @Operation(summary = "获取用户的所有账户的交易记录")
    public ApiResult<List<TransRecordList>> getAllAccountRecord(@RequestBody SelectTransRecordReq selectTransRecordReq) {
        return transRecordService.getAllAccountRecord(selectTransRecordReq);
    }

}
